package com.example.service.impl;

import com.example.service.OrderMainService;
import com.example.model.OrderMainDTO;
import com.example.entity.OrderMain;
import com.example.manager.OrderMainManager;
import com.example.mapper.OrderMainMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 订单主表 服务实现类
 * @author CodeGenerator
 * @date 2025-08-30
 */
@Service
public class OrderMainServiceImpl implements OrderMainService {

    @Autowired
    private OrderMainManager orderMainManager;

    @Autowired
    private OrderMainMapper orderMainMapper;

    @Override
    public int insert(OrderMainDTO orderMainDTO) {
        OrderMain orderMain = orderMainMapper.toEntity(orderMainDTO);
        return orderMainManager.insert(orderMain);
    }

    @Override
    public int update(OrderMainDTO orderMainDTO) {
        OrderMain orderMain = orderMainMapper.toEntity(orderMainDTO);
        return orderMainManager.update(orderMain);
    }

    @Override
    public int deleteById(Integer id) {
        return orderMainManager.deleteById(id);
    }

    @Override
    public OrderMainDTO selectById(Integer id) {
        OrderMain orderMain = orderMainManager.selectById(id);
        return orderMainMapper.toDTO(orderMain);
    }

    @Override
    public List<OrderMainDTO> selectAll() {
        List<OrderMain> list = orderMainManager.selectAll();
        return list.stream()
                .map(orderMainMapper::toDTO)
                .collect(Collectors.toList());
    }
}

